package com.ruoyi.project.WebMoudle.shopMessage.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.WebMoudle.shopMessage.domain.ShopMessage;
import com.ruoyi.project.WebMoudle.shopMessage.service.IShopMessageService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 商铺消息Controller
 * 
 * @author ruoyi
 * @date 2020-09-09
 */
@Controller
@RequestMapping("/shopMessage/shopMessage")
public class ShopMessageController extends BaseController
{
    private String prefix = "shopMessage/shopMessage";

    @Autowired
    private IShopMessageService shopMessageService;

    @RequiresPermissions("shopMessage:shopMessage:view")
    @GetMapping()
    public String shopMessage()
    {
        return prefix + "/shopMessage";
    }

    /**
     * 查询商铺消息列表
     */
    @RequiresPermissions("shopMessage:shopMessage:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ShopMessage shopMessage)
    {
        startPage();
        List<ShopMessage> list = shopMessageService.selectShopMessageList(shopMessage);
        return getDataTable(list);
    }

    /**
     * 导出商铺消息列表
     */
    @RequiresPermissions("shopMessage:shopMessage:export")
    @Log(title = "商铺消息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ShopMessage shopMessage)
    {
        List<ShopMessage> list = shopMessageService.selectShopMessageList(shopMessage);
        ExcelUtil<ShopMessage> util = new ExcelUtil<ShopMessage>(ShopMessage.class);
        return util.exportExcel(list, "shopMessage");
    }

    /**
     * 新增商铺消息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商铺消息
     */
    @RequiresPermissions("shopMessage:shopMessage:add")
    @Log(title = "商铺消息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ShopMessage shopMessage)
    {
        return toAjax(shopMessageService.insertShopMessage(shopMessage));
    }

    /**
     * 修改商铺消息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ShopMessage shopMessage = shopMessageService.selectShopMessageById(id);
        mmap.put("shopMessage", shopMessage);
        return prefix + "/edit";
    }

    /**
     * 修改保存商铺消息
     */
    @RequiresPermissions("shopMessage:shopMessage:edit")
    @Log(title = "商铺消息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ShopMessage shopMessage)
    {
        return toAjax(shopMessageService.updateShopMessage(shopMessage));
    }

    /**
     * 删除商铺消息
     */
    @RequiresPermissions("shopMessage:shopMessage:remove")
    @Log(title = "商铺消息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(shopMessageService.deleteShopMessageByIds(ids));
    }
}
